package com.yuexun.dhdoctor.module.Contract.ui;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.base.BaseKJActivity;
import com.yuexun.dhdoctor.widget.ActionSheetDialog;

import org.kymjs.kjframe.ui.ViewInject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by work-jx on 2016/7/18.
 */
public class Act_PeopleDetail extends BaseKJActivity {

    @Bind(R.id.peopledetail_icon)
    ImageView peopledetailIcon;
    @Bind(R.id.peopledetail_name)
    TextView peopledetailName;
    @Bind(R.id.peopledetail_jobnum)
    TextView peopledetailJobnum;
    @Bind(R.id.peopledetail_phone01)
    TextView peopledetailPhone01;
    @Bind(R.id.peopledetail_phone02)
    TextView peopledetailPhone02;
    @Bind(R.id.peopledetail_phone03)
    TextView peopledetailPhone03;
    @Bind(R.id.peopledetail_dept)
    TextView peopledetailDept;
    @Bind(R.id.peopledetail_job)
    TextView peopledetailJob;
    @Bind(R.id.peopledetail_mail)
    TextView peopledetailMail;
    @Bind(R.id.peopledetail_bottom_ll)
    LinearLayout peopledetailBottomLl;

    private String mobile_str, phone_str, phone2_str;
    boolean iscall = false;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_peopledetail);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        mobile_str = getIntent().getExtras().getString("mobile");
        phone_str = getIntent().getExtras().getString("phone");
        phone2_str = getIntent().getExtras().getString("phone2");
        peopledetailName.setText(getIntent().getExtras().getString("name"));
        peopledetailPhone01.setText(getIntent().getExtras().getString("mobile"));
        peopledetailPhone02.setText(getIntent().getExtras().getString("phone"));
        peopledetailPhone03.setText(getIntent().getExtras().getString("phone2"));
        peopledetailDept.setText(getIntent().getExtras().getString("dept"));
        peopledetailJob.setText(getIntent().getExtras().getString("job"));
        peopledetailMail.setText(getIntent().getExtras().getString("mail"));
        peopledetailJobnum.setText("工号 " + getIntent().getExtras().getString("jobnum"));
    }

    @Override
    @OnClick({R.id.back, R.id.peopledetail_send, R.id.peopledetail_call})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.peopledetail_send:
                if (mobile_str.isEmpty() && phone_str.isEmpty() && phone2_str.isEmpty()) {
                    ViewInject.toast("没有联系方式");
                } else {
                    iscall = false;
                    showDialog();
                }
                break;
            case R.id.peopledetail_call:
                if (mobile_str.isEmpty() && phone_str.isEmpty() && phone2_str.isEmpty()) {
                    ViewInject.toast("没有联系方式");
                } else {
                    iscall = true;
                    showDialog();
                }
                break;
        }
    }

    private void showDialog() {
        ActionSheetDialog actionSheetDialog;
        actionSheetDialog = new ActionSheetDialog(this).builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(false);

        if (!TextUtils.isEmpty(mobile_str)) {
            actionSheetDialog.addSheetItem(mobile_str, ActionSheetDialog.SheetItemColor.Blue,
                    new ActionSheetDialog.OnSheetItemClickListener() {
                        @Override
                        public void onClick(int which) {
                            if (!iscall) {
                                Uri uri1 = Uri.parse("smsto:" + mobile_str);
                                Intent intentMSM = new Intent(Intent.ACTION_SENDTO, uri1);
                                startActivity(intentMSM);
                            } else {
                                Uri uri2 = Uri.parse("tel:" + mobile_str);
                                Intent intentPhone = new Intent(Intent.ACTION_DIAL, uri2);
                                startActivity(intentPhone);
                            }
                        }
                    });
        }
        if (!TextUtils.isEmpty(phone_str)) {
            actionSheetDialog.addSheetItem(phone_str, ActionSheetDialog.SheetItemColor.Blue,
                    new ActionSheetDialog.OnSheetItemClickListener() {
                        @Override
                        public void onClick(int which) {
                            if (!iscall) {
                                Uri uri1 = Uri.parse("smsto:" + phone_str);
                                Intent intentMSM = new Intent(Intent.ACTION_SENDTO, uri1);
                                startActivity(intentMSM);
                            } else {
                                Uri uri2 = Uri.parse("tel:" + phone_str);
                                Intent intentPhone = new Intent(Intent.ACTION_DIAL, uri2);
                                startActivity(intentPhone);
                            }
                        }
                    });
        }
        if (!TextUtils.isEmpty(phone2_str)) {
            actionSheetDialog.addSheetItem(phone2_str, ActionSheetDialog.SheetItemColor.Blue,
                    new ActionSheetDialog.OnSheetItemClickListener() {
                        @Override
                        public void onClick(int which) {
                            if (!iscall) {
                                Uri uri1 = Uri.parse("smsto:" + phone2_str);
                                Intent intentMSM = new Intent(Intent.ACTION_SENDTO, uri1);
                                startActivity(intentMSM);
                            } else {
                                Uri uri2 = Uri.parse("tel:" + phone2_str);
                                Intent intentPhone = new Intent(Intent.ACTION_DIAL, uri2);
                                startActivity(intentPhone);
                            }
                        }
                    });
        }
        actionSheetDialog.show();
    }
}
